package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class Delete implements Ioperation{
    @Override
    public void work(BookList bookList) {
        Scanner scan = new Scanner(System.in);
        System.out.println("输入你要删除的书的书名：");
        String bookName = scan.nextLine();
        int count = bookList.getCur();

        for (int i = 0; i < count; i++) {
            Book book = bookList.getBooks(i);
            if(book.getName().equals(bookName)){
                for (int j = i; j < count - 1; j++) {
                    bookList.setBooks(j,bookList.getBooks(j+1));
                }
                bookList.setCur(count - 1);
                System.out.println("删除成功......");
                return;
            }
        }
        System.out.println("没有该书......");
    }
}
